<!doctype html>
<html lang="zh-CN">
<head>
  <base href="https://www.nodeapp.cn/util.html" />
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>工具集 | Node.js 中文文档 | Node.js 中文网</title>
  <meta name="description" content="Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。Node.js 使用了一个事件驱动、非阻塞式 I/O 的模型，使其轻量又高效。Node.js 的包管理器 npm，是全球最大的开源库生态系统。">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://www.nodeapp.cn/util.html">
  <link rel="apple-touch-icon" href="apple-touch-icon.png">
  <link rel="icon" sizes="32x32" type="image/png" href="favicon.png">
  
  <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?acdf78480f7f8f2b23b812565a5868e0";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</head>
<body class="alt apidoc" id="api-section-util">
  <div id="content" class="clearfix">
    <div id="column1" data-id="util" class="interior">
      <header>
        <h1>Node.js v8.x 中文文档</h1>
        <hr>
      </header>

      <div id="toc">
        <h2>目录</h2>
        <ul>
<li><span class="stability_2"><a href="#util_util">util (实用工具)</a></span><ul>
<li><span class="stability_undefined"><a href="#util_util_callbackify_original">util.callbackify(original)</a></span></li>
<li><span class="stability_undefined"><a href="#util_util_debuglog_section">util.debuglog(section)</a></span></li>
<li><span class="stability_undefined"><a href="#util_util_deprecate_function_string">util.deprecate(function, string)</a></span></li>
<li><span class="stability_undefined"><a href="#util_util_format_format_args">util.format(format[, ...args])</a></span></li>
<li><span class="stability_undefined"><a href="#util_util_inherits_constructor_superconstructor">util.inherits(constructor, superConstructor)</a></span></li>
<li><span class="stability_undefined"><a href="#util_util_inspect_object_options">util.inspect(object[, options])</a></span><ul>
<li><span class="stability_undefined"><a href="#util_customizing_util_inspect_colors">自定义 <code>util.inspect</code> 颜色</a></span></li>
<li><span class="stability_undefined"><a href="#util_custom_inspection_functions_on_objects">自定义对象的查看函数</a></span></li>
<li><span class="stability_undefined"><a href="#util_util_inspect_custom">util.inspect.custom</a></span></li>
<li><span class="stability_undefined"><a href="#util_util_inspect_defaultoptions">util.inspect.defaultOptions</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#util_util_promisify_original">util.promisify(original)</a></span><ul>
<li><span class="stability_undefined"><a href="#util_custom_promisified_functions">Custom promisified functions</a></span></li>
<li><span class="stability_undefined"><a href="#util_util_promisify_custom">util.promisify.custom</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#util_class_util_textdecoder">Class: util.TextDecoder</a></span><ul>
<li><span class="stability_undefined"><a href="#util_whatwg_supported_encodings">WHATWG Supported Encodings</a></span><ul>
<li><span class="stability_undefined"><a href="#util_encodings_supported_without_icu">Encodings Supported Without ICU</a></span></li>
<li><span class="stability_undefined"><a href="#util_encodings_supported_by_default_with_icu">Encodings Supported by Default (With ICU)</a></span></li>
<li><span class="stability_undefined"><a href="#util_encodings_requiring_full_icu_data">Encodings Requiring Full ICU Data</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#util_new_textdecoder_encoding_options">new TextDecoder([encoding[, options]])</a></span></li>
<li><span class="stability_undefined"><a href="#util_textdecoder_decode_input_options">textDecoder.decode([input[, options]])</a></span></li>
<li><span class="stability_undefined"><a href="#util_textdecoder_encoding">textDecoder.encoding</a></span></li>
<li><span class="stability_undefined"><a href="#util_textdecoder_fatal">textDecoder.fatal</a></span></li>
<li><span class="stability_undefined"><a href="#util_textdecoder_ignorebom">textDecoder.ignoreBOM</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#util_class_util_textencoder">Class: util.TextEncoder</a></span><ul>
<li><span class="stability_undefined"><a href="#util_textencoder_encode_input">textEncoder.encode([input])</a></span></li>
<li><span class="stability_undefined"><a href="#util_textencoder_encoding">textEncoder.encoding</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#util_deprecated_apis">废弃的 API</a></span><ul>
<li><span class="stability_0"><a href="#util_util_extend_target_source">util._extend(target, source)</a></span></li>
<li><span class="stability_0"><a href="#util_util_debug_string">util.debug(string)</a></span></li>
<li><span class="stability_0"><a href="#util_util_error_strings">util.error([...strings])</a></span></li>
<li><span class="stability_0"><a href="#util_util_isarray_object">util.isArray(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isboolean_object">util.isBoolean(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isbuffer_object">util.isBuffer(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isdate_object">util.isDate(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_iserror_object">util.isError(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isfunction_object">util.isFunction(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isnull_object">util.isNull(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isnullorundefined_object">util.isNullOrUndefined(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isnumber_object">util.isNumber(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isobject_object">util.isObject(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isprimitive_object">util.isPrimitive(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isregexp_object">util.isRegExp(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isstring_object">util.isString(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_issymbol_object">util.isSymbol(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_isundefined_object">util.isUndefined(object)</a></span></li>
<li><span class="stability_0"><a href="#util_util_log_string">util.log(string)</a></span></li>
<li><span class="stability_0"><a href="#util_util_print_strings">util.print([...strings])</a></span></li>
<li><span class="stability_0"><a href="#util_util_puts_strings">util.puts([...strings])</a></span></li>
</ul>
</li>
</ul>
</li>
</ul>

      </div>
<div id="apicontent">
        <h1>util (实用工具)<span><a class="mark" href="#util_util" id="util_util">#</a></span></h1>
<!--introduced_in=v0.10.0-->
<div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">稳定性: 2</a> - 稳定的</div><p><code>util</code> 模块主要用于支持 Node.js 内部 API 的需求。
大部分实用工具也可用于应用程序与模块开发者。
它可以通过以下方式使用：</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);
</code></pre>
<h2>util.callbackify(original)<span><a class="mark" href="#util_util_callbackify_original" id="util_util_callbackify_original">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v8.2.0</span>
</div><ul>
<li><code>original</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a>  <code>async</code> 异步函数</li>
<li>Returns: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 传统回调函数</li>
</ul>
<p>将 <code>async</code> 异步函数(或者一个返回值为 Promise 的函数)转换成遵循异常优先的回调风格的函数，例如将 <code>(err, value) =&gt; ...</code> 回调作为最后一个参数。在回调函数中, 第一个参数 err 为 Promise rejected 的原因 (如果 Promise 状态为 resolved , err为 <code>null</code> ),第二个参数则是 Promise 状态为 resolved 时的返回值.</p>
<p>例如 :</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

async function fn() {
  return &apos;hello world&apos;;
}
const callbackFunction = util.callbackify(fn);

callbackFunction((err, ret) =&gt; {
  if (err) throw err;
  console.log(ret);
});
</code></pre>
<p>将会打印出:</p>
<pre><code class="lang-txt">hello world
</code></pre>
<p><strong>注意</strong>:</p>
<ul>
<li><p>回调函数是异步执行的, 并且有异常堆栈错误追踪. 
如果回调函数抛出一个异常, 进程会触发一个 <a href="process.html#process_event_uncaughtexception"><code>&apos;uncaughtException&apos;</code></a> 异常, 如果没有被捕获, 进程将会退出.</p>
</li>
<li><p><code>null</code> 在回调函数中作为一个参数有其特殊的意义, 如果回调函数的首个参数为 Promise rejected 的原因且带有返回值, 且值可以转换成布尔值 <code>false</code>, 这个值会被封装在 <code>Error</code> 对象里, 可以通过属性 <code>reason</code> 获取.</p>
<pre><code class="lang-js">function fn() {
  return Promise.reject(null);
}
const callbackFunction = util.callbackify(fn);

callbackFunction((err, ret) =&gt; {
  // When the Promise was rejected with `null` it is wrapped with an Error and
  // the original value is stored in `reason`.
  err &amp;&amp; err.hasOwnProperty(&apos;reason&apos;) &amp;&amp; err.reason === null;  // true
});
</code></pre>
</li>
</ul>
<h2>util.debuglog(section)<span><a class="mark" href="#util_util_debuglog_section" id="util_util_debuglog_section">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.11.3</span>
</div><ul>
<li><code>section</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 一个字符串，指定要为应用的哪些部分创建 <code>debuglog</code> 函数。
<code>debuglog</code> 函数要为哪些应用创建。</li>
<li>返回: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> 日志函数</li>
</ul>
<p><code>util.debuglog()</code> 方法用于创建一个函数，基于 <code>NODE_DEBUG</code> 环境变量的存在与否有条件地写入调试信息到 <code>stderr</code>。
如果 <code>section</code> 名称在环境变量的值中，则返回的函数类似于 <a href="console.html#console_console_error_data_args"><code>console.error()</code></a>。
否则，返回的函数是一个空操作。</p>
<p>例子：</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);
const debuglog = util.debuglog(&apos;foo&apos;);

debuglog(&apos;hello from foo [%d]&apos;, 123);
</code></pre>
<p>如果程序在环境中运行时带上 <code>NODE_DEBUG=foo</code>，则输出类似如下： </p>
<pre><code class="lang-txt">FOO 3245: hello from foo [123]
</code></pre>
<p>其中 <code>3245</code> 是进程 id。
如果运行时没带上环境变量集合，则不会打印任何东西。</p>
<p><code>NODE_DEBUG</code> 环境变量中可指定多个由逗号分隔的 <code>section</code> 名称。
例如：<code>NODE_DEBUG=fs,net,tls</code>。</p>
<h2>util.deprecate(function, string)<span><a class="mark" href="#util_util_deprecate_function_string" id="util_util_deprecate_function_string">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v0.8.0</span>
</div><p><code>util.deprecate()</code> 方法会包装给定的 <code>function</code> 或类，并标记为废弃的。</p>
<!-- eslint-disable prefer-rest-params -->
<pre><code class="lang-js">const util = require(&apos;util&apos;);

exports.puts = util.deprecate(function() {
  for (let i = 0, len = arguments.length; i &lt; len; ++i) {
    process.stdout.write(arguments[i] + &apos;\n&apos;);
  }
}, &apos;util.puts: 使用 console.log 代替&apos;);
</code></pre>
<p>当被调用时，<code>util.deprecate()</code> 会返回一个函数，这个函数会使用 <code>process.on(&apos;warning&apos;)</code> 事件触发一个 <code>DeprecationWarning</code>。
默认情况下，警告只在首次被调用时才会被触发并打印到 <code>stderr</code>。
警告被触发之后，被包装的 <code>function</code> 会被调用。</p>
<p>如果使用了 <code>--no-deprecation</code> 或 <code>--no-warnings</code> 命令行标记，或 <code>process.noDeprecation</code> 属性在首次废弃警告之前被设为 <code>true</code>，则 <code>util.deprecate()</code> 方法什么也不做。</p>
<p>如果设置了 <code>--trace-deprecation</code> 或 <code>--trace-warnings</code> 命令行标记，或 <code>process.traceDeprecation</code> 属性被设为 <code>true</code>，则废弃的函数首次被调用时会把警告与堆栈追踪打印到 <code>stderr</code>。</p>
<p>如果设置了 <code>--throw-deprecation</code> 命令行标记，或 <code>process.throwDeprecation</code> 属性被设为 <code>true</code>，则当废弃的函数被调用时会抛出一个异常。</p>
<p><code>--throw-deprecation</code> 命令行标记和 <code>process.throwDeprecation</code> 属性优先于 <code>--trace-deprecation</code> 和 <code>process.traceDeprecation</code>。</p>
<h2>util.format(format[, ...args])<span><a class="mark" href="#util_util_format_format_args" id="util_util_format_format_args">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>版本历史</summary>
<table>
<tbody><tr><th>版本</th><th>变更</th></tr>
<tr><td>v8.4.0</td>
<td><p>The <code>%o</code> and <code>%O</code> specifiers are supported now.</p>
</td></tr>
<tr><td>v0.5.3</td>
<td><p><span>新增于: v0.5.3</span></p>
</td></tr>
</tbody></table>
</details>
</div><ul>
<li><code>format</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> 一个类似 <code>printf</code> 的格式字符串。</li>
</ul>
<p><code>util.format()</code> 方法返回一个格式化后的字符串，使用第一个参数作为一个类似 <code>printf</code> 的格式。</p>
<p>第一个参数是一个字符串，包含零个或多个占位符。
每个占位符会被对应参数转换后的值所替换。
支持的占位符有：</p>
<ul>
<li><code>%s</code> - 字符串。</li>
<li><code>%d</code> - 数值（整数或浮点数）。</li>
<li><code>%i</code> - Integer.</li>
<li><code>%f</code> - Floating point value.</li>
<li><code>%j</code> - JSON。如果参数包含循环引用，则用字符串 <code>&apos;[Circular]&apos;</code> 替换。</li>
<li><code>%o</code> - Object. A string representation of an object
with generic JavaScript object formatting.
Similar to <code>util.inspect()</code> with options <code>{ showHidden: true, depth: 4, showProxy: true }</code>.
This will show the full object including non-enumerable symbols and properties.</li>
<li><code>%O</code> - Object. A string representation of an object
with generic JavaScript object formatting.
Similar to <code>util.inspect()</code> without options.
This will show the full object not including non-enumerable symbols and properties.</li>
<li><code>%%</code> - 单个百分号（<code>&apos;%&apos;</code>）。不消耗参数。</li>
</ul>
<p>如果占位符没有对应的参数，则占位符不被替换。</p>
<pre><code class="lang-js">util.format(&apos;%s:%s&apos;, &apos;foo&apos;);
// 返回: &apos;foo:%s&apos;
</code></pre>
<p>如果传入 <code>util.format()</code> 方法的参数比占位符的数量多，则多出的参数会被强制转换为字符串，然后拼接到返回的字符串，参数之间用一个空格分隔。
Excessive arguments whose
<code>typeof</code> is <code>&apos;object&apos;</code> or <code>&apos;symbol&apos;</code> (except <code>null</code>) will be transformed by
<code>util.inspect()</code>.</p>
<pre><code class="lang-js">util.format(&apos;%s:%s&apos;, &apos;foo&apos;, &apos;bar&apos;, &apos;baz&apos;); // &apos;foo:bar baz&apos;
</code></pre>
<p>如果第一个参数不是一个字符串，则 <code>util.format()</code> 返回一个所有参数用空格分隔并连在一起的字符串。
每个参数都使用 <code>util.inspect()</code> 转换为一个字符串。</p>
<pre><code class="lang-js">util.format(1, 2, 3); // &apos;1 2 3&apos;
</code></pre>
<p>If only one argument is passed to <code>util.format()</code>, it is returned as it is
without any formatting.</p>
<pre><code class="lang-js">util.format(&apos;%% %s&apos;); // &apos;%% %s&apos;
</code></pre>
<h2>util.inherits(constructor, superConstructor)<span><a class="mark" href="#util_util_inherits_constructor_superconstructor" id="util_util_inherits_constructor_superconstructor">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>版本历史</summary>
<table>
<tbody><tr><th>版本</th><th>变更</th></tr>
<tr><td>v5.0.0</td>
<td><p>The <code>constructor</code> parameter can refer to an ES6 class now.</p>
</td></tr>
<tr><td>v0.3.0</td>
<td><p><span>新增于: v0.3.0</span></p>
</td></tr>
</tbody></table>
</details>
</div><p>注意，不建议使用 <code>util.inherits()</code>。
请使用 ES6 的 <code>class</code> 和 <code>extends</code> 关键词获得语言层面的继承支持。
注意，这两种方式是<a href="https://github.com/nodejs/node/issues/4179">语义上不兼容的</a>。</p>
<ul>
<li><code>constructor</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
<li><code>superConstructor</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>从一个<a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/constructor">构造函数</a>中继承原型方法到另一个。
<code>constructor</code> 的原型会被设置到一个从 <code>superConstructor</code> 创建的新对象上。</p>
<p><code>superConstructor</code> 可通过 <code>constructor.super_</code> 属性访问。</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);
const EventEmitter = require(&apos;events&apos;);

function MyStream() {
  EventEmitter.call(this);
}

util.inherits(MyStream, EventEmitter);

MyStream.prototype.write = function(data) {
  this.emit(&apos;data&apos;, data);
};

const stream = new MyStream();

console.log(stream instanceof EventEmitter); // true
console.log(MyStream.super_ === EventEmitter); // true

stream.on(&apos;data&apos;, (data) =&gt; {
  console.log(`接收的数据：&quot;${data}&quot;`);
});
stream.write(&apos;运作良好！&apos;); // 接收的数据：&quot;运作良好！&quot;
</code></pre>
<p>例子：使用 ES6 的 <code>class</code> 和 <code>extends</code>：</p>
<pre><code class="lang-js">const EventEmitter = require(&apos;events&apos;);

class MyStream extends EventEmitter {
  write(data) {
    this.emit(&apos;data&apos;, data);
  }
}

const stream = new MyStream();

stream.on(&apos;data&apos;, (data) =&gt; {
  console.log(`接收的数据：&quot;${data}&quot;`);
});
stream.write(&apos;使用 ES6&apos;);

</code></pre>
<h2>util.inspect(object[, options])<span><a class="mark" href="#util_util_inspect_object_options" id="util_util_inspect_object_options">#</a></span></h2>
<div class="api_metadata">
<details class="changelog"><summary>版本历史</summary>
<table>
<tbody><tr><th>版本</th><th>变更</th></tr>
<tr><td>v6.6.0</td>
<td><p>Custom inspection functions can now return <code>this</code>.</p>
</td></tr>
<tr><td>v6.3.0</td>
<td><p>The <code>breakLength</code> option is supported now.</p>
</td></tr>
<tr><td>v6.1.0</td>
<td><p>The <code>maxArrayLength</code> option is supported now; in particular, long arrays are truncated by default.</p>
</td></tr>
<tr><td>v6.1.0</td>
<td><p>The <code>showProxy</code> option is supported now.</p>
</td></tr>
<tr><td>v0.3.0</td>
<td><p><span>新增于: v0.3.0</span></p>
</td></tr>
</tbody></table>
</details>
</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span> 任何 JavaScript 原始值或对象。</li>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>showHidden</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 如果为 <code>true</code>，则 <code>object</code> 的不可枚举的符号与属性也会被包括在格式化后的结果中。
默认为 <code>false</code>。</li>
<li><code>depth</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 指定格式化 <code>object</code> 时递归的次数。
这对查看大型复杂对象很有用。
默认为 <code>2</code>。
若要无限地递归则传入 <code>null</code>。</li>
<li><code>colors</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 如果为 <code>true</code>，则输出样式使用 ANSI 颜色代码。
默认为 <code>false</code>。
颜色可自定义，详见<a href="#util_customizing_util_inspect_colors">自定义 <code>util.inspect</code> 颜色</a>。</li>
<li><code>customInspect</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 如果为 <code>false</code>，则 <code>object</code> 上自定义的 <code>inspect(depth, opts)</code> 函数不会被调用。
默认为 <code>true</code>。</li>
<li><code>showProxy</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> 如果为 <code>true</code>，则 <code>Proxy</code> 对象的对象和函数会展示它们的 <code>target</code> 和 <code>handler</code> 对象。
默认为 <code>false</code>。</li>
<li><code>maxArrayLength</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 指定格式化时数组和 <code>TypedArray</code> 元素能包含的最大数量。
默认为 <code>100</code>。
设为 <code>null</code> 则显式全部数组元素。
设为 <code>0</code> 或负数则不显式数组元素。</li>
<li><code>breakLength</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> 一个对象的键被拆分成多行的长度。
设为 <code>Infinity</code> 则格式化一个对象为单行。
默认为 <code>60</code>。</li>
</ul>
</li>
</ul>
<p><code>util.inspect()</code> 方法返回 <code>object</code> 的字符串表示，主要用于调试。
附加的 <code>options</code> 可用于改变格式化字符串的某些方面。</p>
<p>例子，查看 <code>util</code> 对象的所有属性：</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

console.log(util.inspect(util, { showHidden: true, depth: null }));
</code></pre>
<p>当调用到达递归查看的当前 <code>depth</code> 时，值支持自定义的 <code>inspect(depth, opts)</code> 函数，传入 <code>util.inspect()</code> 的选项对象也一样。</p>
<h3>自定义 <code>util.inspect</code> 颜色<span><a class="mark" href="#util_customizing_util_inspect_colors" id="util_customizing_util_inspect_colors">#</a></span></h3>
<!-- type=misc -->
<p>可以通过 <code>util.inspect.styles</code> 和 <code>util.inspect.colors</code> 属性全局地自定义 <code>util.inspect</code> 的颜色输出（如果已启用）。</p>
<p><code>util.inspect.styles</code> 是一个映射，关联一个样式名到一个 <code>util.inspect.colors</code> 颜色。</p>
<p>默认的样式与关联的颜色有：</p>
<ul>
<li><code>number</code> - <code>yellow</code></li>
<li><code>boolean</code> - <code>yellow</code></li>
<li><code>string</code> - <code>green</code></li>
<li><code>date</code> - <code>magenta</code></li>
<li><code>regexp</code> - <code>red</code></li>
<li><code>null</code> - <code>bold</code></li>
<li><code>undefined</code> - <code>grey</code></li>
<li><code>special</code> - <code>cyan</code> （暂时只用于函数）</li>
<li><code>name</code> - （无样式）</li>
</ul>
<p>预定义的颜色代码有：<code>white</code>、<code>grey</code>、<code>black</code>、<code>blue</code>、<code>cyan</code>、<code>green</code>、<code>magenta</code>、<code>red</code> 和 <code>yellow</code>。
还有 <code>bold</code>、<code>italic</code>、<code>underline</code> 和 <code>inverse</code> 代码。</p>
<p>颜色样式使用 ANSI 控制码，可能不是所有终端都支持。</p>
<h3>自定义对象的查看函数<span><a class="mark" href="#util_custom_inspection_functions_on_objects" id="util_custom_inspection_functions_on_objects">#</a></span></h3>
<!-- type=misc -->
<p>对象可以定义自己的 <code>[util.inspect.custom](depth, opts)</code>（或已废弃的 <code>inspect(depth, opts)</code>） 函数，<code>util.inspect()</code> 会调用并使用查看对象时的结果：</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

class Box {
  constructor(value) {
    this.value = value;
  }

  [util.inspect.custom](depth, options) {
    if (depth &lt; 0) {
      return options.stylize(&apos;[Box]&apos;, &apos;special&apos;);
    }

    const newOptions = Object.assign({}, options, {
      depth: options.depth === null ? null : options.depth - 1
    });

    // 五个空格的填充，因为那是 &quot;Box&lt; &quot; 的大小。
    const padding = &apos; &apos;.repeat(5);
    const inner = util.inspect(this.value, newOptions)
                      .replace(/\n/g, `\n${padding}`);
    return `${options.stylize(&apos;Box&apos;, &apos;special&apos;)}&lt; ${inner} &gt;`;
  }
}

const box = new Box(true);

util.inspect(box);
// 返回: &quot;Box&lt; true &gt;&quot;
</code></pre>
<p>自定义的 <code>[util.inspect.custom](depth, opts)</code> 函数通常返回一个字符串，但也可以返回一个任何类型的值，它会相应地被 <code>util.inspect()</code> 格式化。</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

const obj = { foo: &apos;这个不会出现在 inspect() 的输出中&apos; };
obj[util.inspect.custom] = (depth) =&gt; {
  return { bar: &apos;baz&apos; };
};

util.inspect(obj);
// 返回: &quot;{ bar: &apos;baz&apos; }&quot;
</code></pre>
<h3>util.inspect.custom<span><a class="mark" href="#util_util_inspect_custom" id="util_util_inspect_custom">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v6.6.0</span>
</div><p>一个符号，可被用于声明自定义的查看函数，详见<a href="#util_custom_inspection_functions_on_objects">自定义对象的查看函数</a>。</p>
<h3>util.inspect.defaultOptions<span><a class="mark" href="#util_util_inspect_defaultoptions" id="util_util_inspect_defaultoptions">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v6.4.0</span>
</div><p><code>defaultOptions</code> 值允许对被 <code>util.inspect</code> 使用的默认选项进行自定义。
这对 <code>console.log</code> 或 <code>util.format</code> 等显式调用 <code>util.inspect</code> 的函数很有用。
它需被设为一个对象，包含一个或多个有效的 <a href="#util_util_inspect_object_options"><code>util.inspect()</code></a> 选项。
也支持直接设置选项的属性。</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);
const arr = Array(101).fill(0);

console.log(arr); // 打印截断的数组
util.inspect.defaultOptions.maxArrayLength = null;
console.log(arr); // 打印完整的数组
</code></pre>
<h2>util.promisify(original)<span><a class="mark" href="#util_util_promisify_original" id="util_util_promisify_original">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v8.0.0</span>
</div><ul>
<li><code>original</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
<li>Returns: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>让一个遵循异常优先的回调风格的函数， 即 <code>(err, value) =&gt; ...</code> 回调函数是最后一个参数, 返回一个返回值是一个 promise 版本的函数。</p>
<p>例如：</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);
const fs = require(&apos;fs&apos;);

const stat = util.promisify(fs.stat);
stat(&apos;.&apos;).then((stats) =&gt; {
  // Do something with `stats`
}).catch((error) =&gt; {
  // Handle the error.
});
</code></pre>
<p>或者，使用<code>async function</code>获得等效的效果:</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);
const fs = require(&apos;fs&apos;);

const stat = util.promisify(fs.stat);

async function callStat() {
  const stats = await stat(&apos;.&apos;);
  console.log(`This directory is owned by ${stats.uid}`);
}
</code></pre>
<p>如果原本就有 <code>original[util.promisify.custom]</code> 属性, <code>promisify</code> 会返回它的值， 查阅 <a href="#util_custom_promisified_functions">Custom promisified functions</a>.</p>
<p><code>promisify()</code> 会在所有情况下假定 <code>original</code> 是一个最后的参数是回调函数的函数，如果它不是，那么返回的函数的返回值为 undefined。 </p>
<h3>Custom promisified functions<span><a class="mark" href="#util_custom_promisified_functions" id="util_custom_promisified_functions">#</a></span></h3>
<p>Using the <code>util.promisify.custom</code> symbol one can override the return value of
<a href="#util_util_promisify_original"><code>util.promisify()</code></a>:</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

function doSomething(foo, callback) {
  // ...
}

doSomething[util.promisify.custom] = (foo) =&gt; {
  return getPromiseSomehow();
};

const promisified = util.promisify(doSomething);
console.log(promisified === doSomething[util.promisify.custom]);
// prints &apos;true&apos;
</code></pre>
<p>This can be useful for cases where the original function does not follow the
standard format of taking an error-first callback as the last argument.</p>
<p>For example, with a function that takes in <code>(foo, onSuccessCallback, onErrorCallback)</code>:</p>
<pre><code class="lang-js">doSomething[util.promisify.custom] = (foo) =&gt; {
  return new Promise((resolve, reject) =&gt; {
    doSomething(foo, resolve, reject);
  });
};
</code></pre>
<p>If <code>promisify.custom</code> is defined but is not a function, <code>promisify()</code> will
throw an error.</p>
<h3>util.promisify.custom<span><a class="mark" href="#util_util_promisify_custom" id="util_util_promisify_custom">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v8.0.0</span>
</div><ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Symbol_type" class="type">&lt;symbol&gt;</a></li>
</ul>
<p>A Symbol that can be used to declare custom promisified variants of functions,
see <a href="#util_custom_promisified_functions">Custom promisified functions</a>.</p>
<h2>Class: util.TextDecoder<span><a class="mark" href="#util_class_util_textdecoder" id="util_class_util_textdecoder">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v8.3.0</span>
</div><p>An implementation of the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a> <code>TextDecoder</code> API.</p>
<pre><code class="lang-js">const decoder = new TextDecoder(&apos;shift_jis&apos;);
let string = &apos;&apos;;
let buffer;
while (buffer = getNextChunkSomehow()) {
  string += decoder.decode(buffer, { stream: true });
}
string += decoder.decode(); // end-of-stream
</code></pre>
<h3>WHATWG Supported Encodings<span><a class="mark" href="#util_whatwg_supported_encodings" id="util_whatwg_supported_encodings">#</a></span></h3>
<p>Per the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a>, the encodings supported by the
<code>TextDecoder</code> API are outlined in the tables below. For each encoding,
one or more aliases may be used.</p>
<p>Different Node.js build configurations support different sets of encodings.
While a very basic set of encodings is supported even on Node.js builds without
ICU enabled, support for some encodings is provided only when Node.js is built
with ICU and using the full ICU data (see <a href="intl.html">Internationalization</a>).</p>
<h4>Encodings Supported Without ICU<span><a class="mark" href="#util_encodings_supported_without_icu" id="util_encodings_supported_without_icu">#</a></span></h4>
<table>
<thead>
<tr>
<th>Encoding</th>
<th>Aliases</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&apos;utf-8&apos;</code></td>
<td><code>&apos;unicode-1-1-utf-8&apos;</code>, <code>&apos;utf8&apos;</code></td>
</tr>
<tr>
<td><code>&apos;utf-16le&apos;</code></td>
<td><code>&apos;utf-16&apos;</code></td>
</tr>
</tbody>
</table>
<h4>Encodings Supported by Default (With ICU)<span><a class="mark" href="#util_encodings_supported_by_default_with_icu" id="util_encodings_supported_by_default_with_icu">#</a></span></h4>
<table>
<thead>
<tr>
<th>Encoding</th>
<th>Aliases</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&apos;utf-8&apos;</code></td>
<td><code>&apos;unicode-1-1-utf-8&apos;</code>, <code>&apos;utf8&apos;</code></td>
</tr>
<tr>
<td><code>&apos;utf-16le&apos;</code></td>
<td><code>&apos;utf-16&apos;</code></td>
</tr>
<tr>
<td><code>&apos;utf-16be&apos;</code></td>
</tr>
</tbody>
</table>
<h4>Encodings Requiring Full ICU Data<span><a class="mark" href="#util_encodings_requiring_full_icu_data" id="util_encodings_requiring_full_icu_data">#</a></span></h4>
<table>
<thead>
<tr>
<th>Encoding</th>
<th>Aliases</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&apos;ibm866&apos;</code></td>
<td><code>&apos;866&apos;</code>, <code>&apos;cp866&apos;</code>, <code>&apos;csibm866&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-2&apos;</code></td>
<td><code>&apos;csisolatin2&apos;</code>, <code>&apos;iso-ir-101&apos;</code>, <code>&apos;iso8859-2&apos;</code>, <code>&apos;iso88592&apos;</code>, <code>&apos;iso_8859-2&apos;</code>, <code>&apos;iso_8859-2:1987&apos;</code>, <code>&apos;l2&apos;</code>, <code>&apos;latin2&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-3&apos;</code></td>
<td><code>&apos;csisolatin3&apos;</code>, <code>&apos;iso-ir-109&apos;</code>, <code>&apos;iso8859-3&apos;</code>, <code>&apos;iso88593&apos;</code>, <code>&apos;iso_8859-3&apos;</code>, <code>&apos;iso_8859-3:1988&apos;</code>, <code>&apos;l3&apos;</code>, <code>&apos;latin3&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-4&apos;</code></td>
<td><code>&apos;csisolatin4&apos;</code>, <code>&apos;iso-ir-110&apos;</code>, <code>&apos;iso8859-4&apos;</code>, <code>&apos;iso88594&apos;</code>, <code>&apos;iso_8859-4&apos;</code>, <code>&apos;iso_8859-4:1988&apos;</code>, <code>&apos;l4&apos;</code>, <code>&apos;latin4&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-5&apos;</code></td>
<td><code>&apos;csisolatincyrillic&apos;</code>, <code>&apos;cyrillic&apos;</code>, <code>&apos;iso-ir-144&apos;</code>, <code>&apos;iso8859-5&apos;</code>, <code>&apos;iso88595&apos;</code>, <code>&apos;iso_8859-5&apos;</code>, <code>&apos;iso_8859-5:1988&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-6&apos;</code></td>
<td><code>&apos;arabic&apos;</code>, <code>&apos;asmo-708&apos;</code>, <code>&apos;csiso88596e&apos;</code>, <code>&apos;csiso88596i&apos;</code>, <code>&apos;csisolatinarabic&apos;</code>, <code>&apos;ecma-114&apos;</code>, <code>&apos;iso-8859-6-e&apos;</code>, <code>&apos;iso-8859-6-i&apos;</code>, <code>&apos;iso-ir-127&apos;</code>, <code>&apos;iso8859-6&apos;</code>, <code>&apos;iso88596&apos;</code>, <code>&apos;iso_8859-6&apos;</code>, <code>&apos;iso_8859-6:1987&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-7&apos;</code></td>
<td><code>&apos;csisolatingreek&apos;</code>, <code>&apos;ecma-118&apos;</code>, <code>&apos;elot_928&apos;</code>, <code>&apos;greek&apos;</code>, <code>&apos;greek8&apos;</code>, <code>&apos;iso-ir-126&apos;</code>, <code>&apos;iso8859-7&apos;</code>, <code>&apos;iso88597&apos;</code>, <code>&apos;iso_8859-7&apos;</code>, <code>&apos;iso_8859-7:1987&apos;</code>, <code>&apos;sun_eu_greek&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-8&apos;</code></td>
<td><code>&apos;csiso88598e&apos;</code>, <code>&apos;csisolatinhebrew&apos;</code>, <code>&apos;hebrew&apos;</code>, <code>&apos;iso-8859-8-e&apos;</code>, <code>&apos;iso-ir-138&apos;</code>, <code>&apos;iso8859-8&apos;</code>, <code>&apos;iso88598&apos;</code>, <code>&apos;iso_8859-8&apos;</code>, <code>&apos;iso_8859-8:1988&apos;</code>, <code>&apos;visual&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-8-i&apos;</code></td>
<td><code>&apos;csiso88598i&apos;</code>, <code>&apos;logical&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-10&apos;</code></td>
<td><code>&apos;csisolatin6&apos;</code>, <code>&apos;iso-ir-157&apos;</code>, <code>&apos;iso8859-10&apos;</code>, <code>&apos;iso885910&apos;</code>, <code>&apos;l6&apos;</code>, <code>&apos;latin6&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-13&apos;</code></td>
<td><code>&apos;iso8859-13&apos;</code>, <code>&apos;iso885913&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-14&apos;</code></td>
<td><code>&apos;iso8859-14&apos;</code>, <code>&apos;iso885914&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-8859-15&apos;</code></td>
<td><code>&apos;csisolatin9&apos;</code>, <code>&apos;iso8859-15&apos;</code>, <code>&apos;iso885915&apos;</code>, <code>&apos;iso_8859-15&apos;</code>, <code>&apos;l9&apos;</code></td>
</tr>
<tr>
<td><code>&apos;koi8-r&apos;</code></td>
<td><code>&apos;cskoi8r&apos;</code>, <code>&apos;koi&apos;</code>, <code>&apos;koi8&apos;</code>, <code>&apos;koi8_r&apos;</code></td>
</tr>
<tr>
<td><code>&apos;koi8-u&apos;</code></td>
<td><code>&apos;koi8-ru&apos;</code></td>
</tr>
<tr>
<td><code>&apos;macintosh&apos;</code></td>
<td><code>&apos;csmacintosh&apos;</code>, <code>&apos;mac&apos;</code>, <code>&apos;x-mac-roman&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-874&apos;</code></td>
<td><code>&apos;dos-874&apos;</code>, <code>&apos;iso-8859-11&apos;</code>, <code>&apos;iso8859-11&apos;</code>, <code>&apos;iso885911&apos;</code>, <code>&apos;tis-620&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1250&apos;</code></td>
<td><code>&apos;cp1250&apos;</code>, <code>&apos;x-cp1250&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1251&apos;</code></td>
<td><code>&apos;cp1251&apos;</code>, <code>&apos;x-cp1251&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1252&apos;</code></td>
<td><code>&apos;ansi_x3.4-1968&apos;</code>, <code>&apos;ascii&apos;</code>, <code>&apos;cp1252&apos;</code>, <code>&apos;cp819&apos;</code>, <code>&apos;csisolatin1&apos;</code>, <code>&apos;ibm819&apos;</code>, <code>&apos;iso-8859-1&apos;</code>, <code>&apos;iso-ir-100&apos;</code>, <code>&apos;iso8859-1&apos;</code>, <code>&apos;iso88591&apos;</code>, <code>&apos;iso_8859-1&apos;</code>, <code>&apos;iso_8859-1:1987&apos;</code>, <code>&apos;l1&apos;</code>, <code>&apos;latin1&apos;</code>, <code>&apos;us-ascii&apos;</code>, <code>&apos;x-cp1252&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1253&apos;</code></td>
<td><code>&apos;cp1253&apos;</code>, <code>&apos;x-cp1253&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1254&apos;</code></td>
<td><code>&apos;cp1254&apos;</code>, <code>&apos;csisolatin5&apos;</code>, <code>&apos;iso-8859-9&apos;</code>, <code>&apos;iso-ir-148&apos;</code>, <code>&apos;iso8859-9&apos;</code>, <code>&apos;iso88599&apos;</code>, <code>&apos;iso_8859-9&apos;</code>, <code>&apos;iso_8859-9:1989&apos;</code>, <code>&apos;l5&apos;</code>, <code>&apos;latin5&apos;</code>, <code>&apos;x-cp1254&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1255&apos;</code></td>
<td><code>&apos;cp1255&apos;</code>, <code>&apos;x-cp1255&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1256&apos;</code></td>
<td><code>&apos;cp1256&apos;</code>, <code>&apos;x-cp1256&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1257&apos;</code></td>
<td><code>&apos;cp1257&apos;</code>, <code>&apos;x-cp1257&apos;</code></td>
</tr>
<tr>
<td><code>&apos;windows-1258&apos;</code></td>
<td><code>&apos;cp1258&apos;</code>, <code>&apos;x-cp1258&apos;</code></td>
</tr>
<tr>
<td><code>&apos;x-mac-cyrillic&apos;</code></td>
<td><code>&apos;x-mac-ukrainian&apos;</code></td>
</tr>
<tr>
<td><code>&apos;gbk&apos;</code></td>
<td><code>&apos;chinese&apos;</code>, <code>&apos;csgb2312&apos;</code>, <code>&apos;csiso58gb231280&apos;</code>, <code>&apos;gb2312&apos;</code>, <code>&apos;gb_2312&apos;</code>, <code>&apos;gb_2312-80&apos;</code>, <code>&apos;iso-ir-58&apos;</code>, <code>&apos;x-gbk&apos;</code></td>
</tr>
<tr>
<td><code>&apos;gb18030&apos;</code></td>
<td></td>
</tr>
<tr>
<td><code>&apos;big5&apos;</code></td>
<td><code>&apos;big5-hkscs&apos;</code>, <code>&apos;cn-big5&apos;</code>, <code>&apos;csbig5&apos;</code>, <code>&apos;x-x-big5&apos;</code></td>
</tr>
<tr>
<td><code>&apos;euc-jp&apos;</code></td>
<td><code>&apos;cseucpkdfmtjapanese&apos;</code>, <code>&apos;x-euc-jp&apos;</code></td>
</tr>
<tr>
<td><code>&apos;iso-2022-jp&apos;</code></td>
<td><code>&apos;csiso2022jp&apos;</code></td>
</tr>
<tr>
<td><code>&apos;shift_jis&apos;</code></td>
<td><code>&apos;csshiftjis&apos;</code>, <code>&apos;ms932&apos;</code>, <code>&apos;ms_kanji&apos;</code>, <code>&apos;shift-jis&apos;</code>, <code>&apos;sjis&apos;</code>, <code>&apos;windows-31j&apos;</code>, <code>&apos;x-sjis&apos;</code></td>
</tr>
<tr>
<td><code>&apos;euc-kr&apos;</code></td>
<td><code>&apos;cseuckr&apos;</code>, <code>&apos;csksc56011987&apos;</code>, <code>&apos;iso-ir-149&apos;</code>, <code>&apos;korean&apos;</code>, <code>&apos;ks_c_5601-1987&apos;</code>, <code>&apos;ks_c_5601-1989&apos;</code>, <code>&apos;ksc5601&apos;</code>, <code>&apos;ksc_5601&apos;</code>, <code>&apos;windows-949&apos;</code></td>
</tr>
</tbody>
</table>
<p><em>Note</em>: The <code>&apos;iso-8859-16&apos;</code> encoding listed in the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a>
is not supported.</p>
<h3>new TextDecoder([encoding[, options]])<span><a class="mark" href="#util_new_textdecoder_encoding_options" id="util_new_textdecoder_encoding_options">#</a></span></h3>
<div class="signature"><ul>
<li><code>encoding</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Identifies the <code>encoding</code> that this <code>TextDecoder</code> instance
supports. Defaults to <code>&apos;utf-8&apos;</code>.</li>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>fatal</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> <code>true</code> if decoding failures are fatal. Defaults to
<code>false</code>. This option is only supported when ICU is enabled (see
<a href="intl.html">Internationalization</a>).</li>
<li><code>ignoreBOM</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> When <code>true</code>, the <code>TextDecoder</code> will include the byte
 order mark in the decoded result. When <code>false</code>, the byte order mark will
 be removed from the output. This option is only used when <code>encoding</code> is
 <code>&apos;utf-8&apos;</code>, <code>&apos;utf-16be&apos;</code> or <code>&apos;utf-16le&apos;</code>. Defaults to <code>false</code>.</li>
</ul>
</li>
</ul>
</div><p>Creates an new <code>TextDecoder</code> instance. The <code>encoding</code> may specify one of the
supported encodings or an alias.</p>
<h3>textDecoder.decode([input[, options]])<span><a class="mark" href="#util_textdecoder_decode_input_options" id="util_textdecoder_decode_input_options">#</a></span></h3>
<div class="signature"><ul>
<li><code>input</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&lt;ArrayBuffer&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&lt;DataView&gt;</a> | 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&lt;TypedArray&gt;</a> An <code>ArrayBuffer</code>, <code>DataView</code> or
Typed Array instance containing the encoded data.</li>
<li><code>options</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a><ul>
<li><code>stream</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a> <code>true</code> if additional chunks of data are expected.
Defaults to <code>false</code>.</li>
</ul>
</li>
<li>Returns: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
</div><p>Decodes the <code>input</code> and returns a string. If <code>options.stream</code> is <code>true</code>, any
incomplete byte sequences occurring at the end of the <code>input</code> are buffered
internally and emitted after the next call to <code>textDecoder.decode()</code>.</p>
<p>If <code>textDecoder.fatal</code> is <code>true</code>, decoding errors that occur will result in a
<code>TypeError</code> being thrown.</p>
<h3>textDecoder.encoding<span><a class="mark" href="#util_textdecoder_encoding" id="util_textdecoder_encoding">#</a></span></h3>
<div class="signature"><ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
</div><p>The encoding supported by the <code>TextDecoder</code> instance.</p>
<h3>textDecoder.fatal<span><a class="mark" href="#util_textdecoder_fatal" id="util_textdecoder_fatal">#</a></span></h3>
<div class="signature"><ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
</div><p>The value will be <code>true</code> if decoding errors result in a <code>TypeError</code> being
thrown.</p>
<h3>textDecoder.ignoreBOM<span><a class="mark" href="#util_textdecoder_ignorebom" id="util_textdecoder_ignorebom">#</a></span></h3>
<div class="signature"><ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&lt;boolean&gt;</a></li>
</ul>
</div><p>The value will be <code>true</code> if the decoding result will include the byte order
mark.</p>
<h2>Class: util.TextEncoder<span><a class="mark" href="#util_class_util_textencoder" id="util_class_util_textencoder">#</a></span></h2>
<div class="api_metadata">
<span>新增于: v8.3.0</span>
</div><p>An implementation of the <a href="https://encoding.spec.whatwg.org/">WHATWG Encoding Standard</a> <code>TextEncoder</code> API. All
instances of <code>TextEncoder</code> only support UTF-8 encoding.</p>
<pre><code class="lang-js">const encoder = new TextEncoder();
const uint8array = encoder.encode(&apos;this is some data&apos;);
</code></pre>
<h3>textEncoder.encode([input])<span><a class="mark" href="#util_textencoder_encode_input" id="util_textencoder_encode_input">#</a></span></h3>
<div class="signature"><ul>
<li><code>input</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The text to encode. Defaults to an empty string.</li>
<li>Returns: 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array" class="type">&lt;Uint8Array&gt;</a></li>
</ul>
</div><p>UTF-8 encodes the <code>input</code> string and returns a <code>Uint8Array</code> containing the
encoded bytes.</p>
<h3>textEncoder.encoding<span><a class="mark" href="#util_textencoder_encoding" id="util_textencoder_encoding">#</a></span></h3>
<div class="signature"><ul>
<li>
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
</div><p>The encoding supported by the <code>TextEncoder</code> instance. Always set to <code>&apos;utf-8&apos;</code>.</p>
<h2>废弃的 API<span><a class="mark" href="#util_deprecated_apis" id="util_deprecated_apis">#</a></span></h2>
<p>以下 API 已被废弃，不应该再被使用。
现存的应用和模块应该使用替代方法更新。</p>
<h3>util._extend(target, source)<span><a class="mark" href="#util_util_extend_target_source" id="util_util_extend_target_source">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.7.5</span><span>废弃于: v6.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的: 使用 <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign"><code>Object.assign()</code></a> 代替。</div><p>The <code>util._extend()</code> method was never intended to be used outside of internal
Node.js modules. The community found and used it anyway.</p>
<p>It is deprecated and should not be used in new code. JavaScript comes with very
similar built-in functionality through <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign"><code>Object.assign()</code></a>.</p>
<h3>util.debug(string)<span><a class="mark" href="#util_util_debug_string" id="util_util_debug_string">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.0</span><span>废弃于: v0.11.3</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的: 使用 <a href="console.html#console_console_error_data_args"><code>console.error()</code></a> 代替。</div><ul>
<li><code>string</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The message to print to <code>stderr</code></li>
</ul>
<p>Deprecated predecessor of <code>console.error</code>.</p>
<h3>util.error([...strings])<span><a class="mark" href="#util_util_error_strings" id="util_util_error_strings">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.0</span><span>废弃于: v0.11.3</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的: 使用 <a href="console.html#console_console_error_data_args"><code>console.error()</code></a> 代替。</div><ul>
<li><code>...strings</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> The message to print to <code>stderr</code></li>
</ul>
<p>Deprecated predecessor of <code>console.error</code>.</p>
<h3>util.isArray(object)<span><a class="mark" href="#util_util_isarray_object" id="util_util_isarray_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.6.0</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Internal alias for <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray"><code>Array.isArray</code></a>.</p>
<p>Returns <code>true</code> if the given <code>object</code> is an <code>Array</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isArray([]);
// Returns: true
util.isArray(new Array());
// Returns: true
util.isArray({});
// Returns: false
</code></pre>
<h3>util.isBoolean(object)<span><a class="mark" href="#util_util_isboolean_object" id="util_util_isboolean_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Boolean</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isBoolean(1);
// Returns: false
util.isBoolean(0);
// Returns: false
util.isBoolean(false);
// Returns: true
</code></pre>
<h3>util.isBuffer(object)<span><a class="mark" href="#util_util_isbuffer_object" id="util_util_isbuffer_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的: 使用 <a href="buffer.html#buffer_class_method_buffer_isbuffer_obj"><code>Buffer.isBuffer()</code></a> 代替。</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Buffer</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isBuffer({ length: 0 });
// Returns: false
util.isBuffer([]);
// Returns: false
util.isBuffer(Buffer.from(&apos;hello world&apos;));
// Returns: true
</code></pre>
<h3>util.isDate(object)<span><a class="mark" href="#util_util_isdate_object" id="util_util_isdate_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.6.0</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Date</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isDate(new Date());
// Returns: true
util.isDate(Date());
// false (without &apos;new&apos; returns a String)
util.isDate({});
// Returns: false
</code></pre>
<h3>util.isError(object)<span><a class="mark" href="#util_util_iserror_object" id="util_util_iserror_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.6.0</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is an <a href="errors.html#errors_class_error"><code>Error</code></a>. Otherwise, returns
<code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isError(new Error());
// Returns: true
util.isError(new TypeError());
// Returns: true
util.isError({ name: &apos;Error&apos;, message: &apos;an error occurred&apos; });
// Returns: false
</code></pre>
<p>Note that this method relies on <code>Object.prototype.toString()</code> behavior. It is
possible to obtain an incorrect result when the <code>object</code> argument manipulates
<code>@@toStringTag</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);
const obj = { name: &apos;Error&apos;, message: &apos;an error occurred&apos; };

util.isError(obj);
// Returns: false
obj[Symbol.toStringTag] = &apos;Error&apos;;
util.isError(obj);
// Returns: true
</code></pre>
<h3>util.isFunction(object)<span><a class="mark" href="#util_util_isfunction_object" id="util_util_isfunction_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Function</code>. Otherwise, returns
<code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

function Foo() {}
const Bar = () =&gt; {};

util.isFunction({});
// Returns: false
util.isFunction(Foo);
// Returns: true
util.isFunction(Bar);
// Returns: true
</code></pre>
<h3>util.isNull(object)<span><a class="mark" href="#util_util_isnull_object" id="util_util_isnull_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is strictly <code>null</code>. Otherwise, returns
<code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isNull(0);
// Returns: false
util.isNull(undefined);
// Returns: false
util.isNull(null);
// Returns: true
</code></pre>
<h3>util.isNullOrUndefined(object)<span><a class="mark" href="#util_util_isnullorundefined_object" id="util_util_isnullorundefined_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is <code>null</code> or <code>undefined</code>. Otherwise,
returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isNullOrUndefined(0);
// Returns: false
util.isNullOrUndefined(undefined);
// Returns: true
util.isNullOrUndefined(null);
// Returns: true
</code></pre>
<h3>util.isNumber(object)<span><a class="mark" href="#util_util_isnumber_object" id="util_util_isnumber_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Number</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isNumber(false);
// Returns: false
util.isNumber(Infinity);
// Returns: true
util.isNumber(0);
// Returns: true
util.isNumber(NaN);
// Returns: true
</code></pre>
<h3>util.isObject(object)<span><a class="mark" href="#util_util_isobject_object" id="util_util_isobject_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is strictly an <code>Object</code> <strong>and</strong> not a
<code>Function</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isObject(5);
// Returns: false
util.isObject(null);
// Returns: false
util.isObject({});
// Returns: true
util.isObject(function() {});
// Returns: false
</code></pre>
<h3>util.isPrimitive(object)<span><a class="mark" href="#util_util_isprimitive_object" id="util_util_isprimitive_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a primitive type. Otherwise, returns
<code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isPrimitive(5);
// Returns: true
util.isPrimitive(&apos;foo&apos;);
// Returns: true
util.isPrimitive(false);
// Returns: true
util.isPrimitive(null);
// Returns: true
util.isPrimitive(undefined);
// Returns: true
util.isPrimitive({});
// Returns: false
util.isPrimitive(function() {});
// Returns: false
util.isPrimitive(/^$/);
// Returns: false
util.isPrimitive(new Date());
// Returns: false
</code></pre>
<h3>util.isRegExp(object)<span><a class="mark" href="#util_util_isregexp_object" id="util_util_isregexp_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.6.0</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>RegExp</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isRegExp(/some regexp/);
// Returns: true
util.isRegExp(new RegExp(&apos;another regexp&apos;));
// Returns: true
util.isRegExp({});
// Returns: false
</code></pre>
<h3>util.isString(object)<span><a class="mark" href="#util_util_isstring_object" id="util_util_isstring_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>string</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isString(&apos;&apos;);
// Returns: true
util.isString(&apos;foo&apos;);
// Returns: true
util.isString(String(&apos;foo&apos;));
// Returns: true
util.isString(5);
// Returns: false
</code></pre>
<h3>util.isSymbol(object)<span><a class="mark" href="#util_util_issymbol_object" id="util_util_issymbol_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is a <code>Symbol</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.isSymbol(5);
// Returns: false
util.isSymbol(&apos;foo&apos;);
// Returns: false
util.isSymbol(Symbol(&apos;foo&apos;));
// Returns: true
</code></pre>
<h3>util.isUndefined(object)<span><a class="mark" href="#util_util_isundefined_object" id="util_util_isundefined_object">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.11.5</span><span>废弃于: v4.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的</div><ul>
<li><code>object</code> <span class="type">&lt;any&gt;</span></li>
</ul>
<p>Returns <code>true</code> if the given <code>object</code> is <code>undefined</code>. Otherwise, returns <code>false</code>.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

const foo = undefined;
util.isUndefined(5);
// Returns: false
util.isUndefined(foo);
// Returns: true
util.isUndefined(null);
// Returns: false
</code></pre>
<h3>util.log(string)<span><a class="mark" href="#util_util_log_string" id="util_util_log_string">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.0</span><span>废弃于: v6.0.0</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的: 使用第三方模块代替。</div><ul>
<li><code>string</code> 
            <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
</ul>
<p>The <code>util.log()</code> method prints the given <code>string</code> to <code>stdout</code> with an included
timestamp.</p>
<pre><code class="lang-js">const util = require(&apos;util&apos;);

util.log(&apos;Timestamped message.&apos;);
</code></pre>
<h3>util.print([...strings])<span><a class="mark" href="#util_util_print_strings" id="util_util_print_strings">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.0</span><span>废弃于: v0.11.3</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的: 使用 <a href="console.html#console_console_log_data_args"><code>console.log()</code></a> 代替。</div><p>Deprecated predecessor of <code>console.log</code>.</p>
<h3>util.puts([...strings])<span><a class="mark" href="#util_util_puts_strings" id="util_util_puts_strings">#</a></span></h3>
<div class="api_metadata">
<span>新增于: v0.3.0</span><span>废弃于: v0.11.3</span>
</div><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">稳定性: 0</a> - 废弃的: 使用 <a href="console.html#console_console_log_data_args"><code>console.log()</code></a> 代替。</div><p>Deprecated predecessor of <code>console.log</code>.</p>

      </div>
    </div>

    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js 中文文档 | Node.js 中文网
        </a>
      </div>
      
        <!-- [start-include:_toc.md] -->
<ul>
<li><a href="documentation.html">关于本文档</a></li>
<li><a href="synopsis.html">用法与例子</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a href="assert.html">断言测试</a></li>
<li><a href="async_hooks.html">异步钩子（Async Hooks）</a></li>
<li><a href="buffer.html">缓存（Buffer）</a></li>
<li><a href="addons.html">C++ 插件</a></li>
<li><a href="n-api.html">C/C++ 插件 - N-API</a></li>
<li><a href="child_process.html">子进程</a></li>
<li><a href="cluster.html">集群（Cluster）</a></li>
<li><a href="cli.html">命令行参数</a></li>
<li><a href="console.html">控制台（Console）</a></li>
<li><a href="crypto.html">加密（Crypto）</a></li>
<li><a href="debugger.html">调试器</a></li>
<li><a href="deprecations.html">废弃的 API</a></li>
<li><a href="dns.html">DNS</a></li>
<li><a href="domain.html">域（Domain）</a></li>
<li><a href="esm.html">ECMAScript 模块</a></li>
<li><a href="errors.html">错误（Errors）</a></li>
<li><a href="events.html">事件（Events）</a></li>
<li><a href="fs.html">文件系统</a></li>
<li><a href="globals.html">全局对象（Globals）</a></li>
<li><a href="http.html">HTTP</a></li>
<li><a href="http2.html">HTTP/2</a></li>
<li><a href="https.html">HTTPS</a></li>
<li><a href="inspector.html">检查工具（Inspector）</a></li>
<li><a href="intl.html">国际化</a></li>
<li><a href="modules.html">模块（Modules）</a></li>
<li><a href="net.html">网络（Net）</a></li>
<li><a href="os.html">操作系统（OS）</a></li>
<li><a href="path.html">路径（Path）</a></li>
<li><a href="perf_hooks.html">性能钩子（Performance Hooks）</a></li>
<li><a href="process.html">进程</a></li>
<li><a href="punycode.html">Punycode</a></li>
<li><a href="querystring.html">查询字符串</a></li>
<li><a href="readline.html">逐行读取</a></li>
<li><a href="repl.html">交互式解释器（REPL）</a></li>
<li><a href="stream.html">流（Stream）</a></li>
<li><a href="string_decoder.html">字符串解码</a></li>
<li><a href="timers.html">定时器（Timers）</a></li>
<li><a href="tls.html">安全传输层（TLS/SSL）</a></li>
<li><a href="tracing.html">事件跟踪（Tracing）</a></li>
<li><a href="tty.html">TTY</a></li>
<li><a href="dgram.html">UDP / 数据报</a></li>
<li><a href="url.html">URL</a></li>
<li><a href="util.html">工具集</a></li>
<li><a href="v8.html">V8</a></li>
<li><a href="vm.html">虚拟机（VM）</a></li>
<li><a href="zlib.html">压缩（ZLIB）</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a href="https://github.com/nodejs/node">GitHub 仓库和问题跟踪</a></li>
<li><a href="https://groups.google.com/group/nodejs">邮件列表</a></li>
</ul>
<!-- [end-include:_toc.md] -->

      
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
</body>
</html>
